package com.wlw.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.wlw.entity.City;
import com.wlw.service.CityService;

import edu.xjsoft.base.orm.support.PropertyFilter;      
@Controller
@RequestMapping("/city/*")
public class CityAction {
	@Autowired
	private CityService cityService;
	
	/**
	 * 春夏秋冬
	 */
	@RequestMapping("list")
	public String list(Model model){
		List<City> chunCities = cityService.chunCities();
		model.addAttribute("chunCities", chunCities);
		List<City> xiaCities = cityService.xiaCities();
		model.addAttribute("xiaCities", xiaCities);
		List<City> qiuCities = cityService.qiuCities();
		model.addAttribute("qiuCities", qiuCities);
		List<City> dongCities = cityService.dongCities();
		model.addAttribute("dongCities", dongCities);
		return "foreground/city";
	}
	@RequestMapping("cityDetail")
	public String cityDetail(HttpServletRequest req,Model model){
		int id = Integer.parseInt(req.getParameter("id"));
		System.out.println("城市细节："+id);
		PropertyFilter filters = new PropertyFilter("id", id);
		List<City> cities = cityService.search(filters);
		if (cities.get(0).getGonglue()!=null) {
			int browserCount = cities.get(0).getGonglue().getBrowserCount()+1;
			cities.get(0).getGonglue().setBrowserCount(browserCount);
			cityService.saveOrUpdate(cities.get(0));
		}
		System.out.println(cities.get(0).getName());
		model.addAttribute("cities", cities);
		return "foreground/cityDetail";
	}
	@RequestMapping("laLongutitude")
	public String laLongutitude(Model model){
		List<City> cities = cityService.loadAll();
		model.addAttribute("cities", cities);
		System.out.println(cities.get(0).getLatitude()+":"+cities.get(0).getLongitude()+":"+cities.get(0).getName());
		System.out.println(cities.get(1).getLatitude()+":"+cities.get(1).getLongitude()+":"+cities.get(1).getName());
		return "foreground/Allmap";
	}
}
